#include "UI.h"

UI::UI(float groundLevel) : groundLevel(groundLevel){
}

UI::~UI(){
}

void UI::initialize(){
	loadData();

	glGenBuffers(1, &positionBufferObject);
	glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
	glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * positionData.size(), positionData.data(), GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glGenBuffers(1, &colorBufferObject);
	glBindBuffer(GL_ARRAY_BUFFER, colorBufferObject);
	glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * colorData.size(), colorData.data(), GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	glGenVertexArrays(1, &vertexArrayObject);
	glBindVertexArray(vertexArrayObject);
	glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
	glBindBuffer(GL_ARRAY_BUFFER, colorBufferObject);
	glEnableVertexAttribArray(1);
	glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);
}

void UI::render(){
	glBindVertexArray(vertexArrayObject);
	glLineWidth(5.0f);
	glDrawArrays(GL_LINES, 0, positionData.size()/2);
	glBindVertexArray(0);
}

void UI::loadData(){
	const int points = 2;
	GLfloat positionDataArray[points * 2] =
	{
		-1.0f, groundLevel,
		 1.0f, groundLevel,
	};
	GLfloat colorDataArray[points * 3] =
	{
		1.0f, 1.0f, 1.0f,
		1.0f, 1.0f, 1.0f,
	};
	for(int i = 0; i != points * 2; ++i)
	{
		positionData.push_back(positionDataArray[i]);
	}
	for(int i = 0; i != points * 3; ++i)
	{
		colorData.push_back(colorDataArray[i]);
	}
}